package com.bp.hearthealth.pulse.lnapps.bp_ui.bp_bean

import android.widget.ImageView
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.databinding.BindingAdapter
import com.bp.hearthealth.pulse.lnapps.BpApplication
import com.bp.hearthealth.pulse.lnapps.R
import com.bp.hearthealth.pulse.lnapps.bp_extension.UIHelperBp
import com.bp.hearthealth.pulse.lnapps.bp_utils.Constants
import com.bp.hearthealth.pulse.lnapps.bp_utils.GlideUtil

object BpBindingAdapters {

    @BindingAdapter("android:setBgResources")
    @JvmStatic
    fun setBgResources(imageView: ConstraintLayout, levelType: Int) {
        when (levelType) {
            1 -> {
                imageView.setBackgroundResource(R.mipmap.low_bg_bp_bp)
            }

            2 -> {
                imageView.setBackgroundResource(R.mipmap.normal_bg_bp)
            }

            3 -> {
                imageView.setBackgroundResource(R.mipmap.high_bg_bp)
            }
        }
    }

    @BindingAdapter("setLineResources")
    @JvmStatic
    fun setLineResources(imageView: ImageView, levelType: Int) {
        when (levelType) {
            1 -> {
                imageView.setImageResource(R.mipmap.low_line_bp)
            }

            2 -> {
                imageView.setImageResource(R.mipmap.normal_line_bp)
            }

            3 -> {
                imageView.setImageResource(R.mipmap.high_line_bp)
            }
        }
    }

    @BindingAdapter("setLevelType")
    @JvmStatic
    fun setLevelType(textView: TextView, levelType: Int) {
        when (levelType) {
            1 -> {
                textView.text = BpApplication.context.getString(R.string._low_str)
            }

            2 -> {
                textView.text = BpApplication.context.getString(R.string._normal_str)
            }

            3 -> {
                textView.text = BpApplication.context.getString(R.string._high_str)
            }
        }
    }

    @BindingAdapter("setRingImage")
    @JvmStatic
    fun setRingImage(imageView: ImageView, enum: Int?) {
        if (enum == null)
            return
        when (enum) {
            0 -> {
                imageView.setImageResource(R.mipmap.blood_pressure_record_ring_first_bp)
            }

            1 -> {
                imageView.setImageResource(R.mipmap.blood_pressure_record_ring_second_bp)
            }

            2 -> {
                imageView.setImageResource(R.mipmap.blood_pressure_record_ring_third_bp)
            }

            3 -> {
                imageView.setImageResource(R.mipmap.blood_pressure_record_ring_fourth_bp)
            }

            4 -> {
                imageView.setImageResource(R.mipmap.blood_pressure_record_ring_fifth_bp)
            }

            else -> {
                imageView.setImageResource(R.mipmap.blood_pressure_record_ring_sixth_bp)
                //Hypertensive_Crisis
            }
        }
    }

    @BindingAdapter("setEmoticonsImage")
    @JvmStatic
    fun setEmoticonsImage(imageView: ImageView, enum: Int?) {
        if (enum == null)
            return
        when (enum) {
            0 -> {
                imageView.setImageResource(R.mipmap.blood_pressure_record_emoticons_second_bp)
            }

            1 -> {
                imageView.setImageResource(R.mipmap.blood_pressure_record_emoticons_first_bp)
            }

            2 -> {
                imageView.setImageResource(R.mipmap.blood_pressure_record_emoticons_third_bp)
            }

            3 -> {
                imageView.setImageResource(R.mipmap.blood_pressure_record_emoticons_fourth_bp)
            }

            4 -> {
                imageView.setImageResource(R.mipmap.blood_pressure_record_emoticons_fifth_bp)
            }

            else -> {
                imageView.setImageResource(R.mipmap.blood_pressure_record_emoticons_sixth_bp)
                //Hypertensive_Crisis
            }
        }
    }

    @BindingAdapter("android:displayCircle")
    @JvmStatic
    fun displayCircle(imageView: ImageView, imageUrl: String?) {
        if (imageUrl?.isNotBlank() == true) {
            GlideUtil.loadImage(imageView.context, imageUrl, imageView)
        }
    }

    @BindingAdapter("android:setEmoticonsText", "android:changeTextColor")
    @JvmStatic
    fun setEmoticonsText(textView: TextView, enum: Int?, changeTextColor: Int) {
        if (enum == null)
            return
        when (enum) {
            0 -> {
                if (changeTextColor == 1) {
                    textView.setTextColor(UIHelperBp.getColor(R.color.color_027FFB))
                }
                textView.text = UIHelperBp.getString(R.string._hypotensive_str)
            }

            1 -> {
                if (changeTextColor == 1) {
                    textView.setTextColor(UIHelperBp.getColor(R.color.color_2BBC8B))
                }
                textView.text = UIHelperBp.getString(R.string._normal_str)
            }

            2 -> {
                if (changeTextColor == 1) {
                    textView.setTextColor(UIHelperBp.getColor(R.color.color_F9DB18))
                }
                textView.text = UIHelperBp.getString(R.string._elevated_str)
            }

            3 -> {
                if (changeTextColor == 1) {
                    textView.setTextColor(UIHelperBp.getColor(R.color.color_FFB900))
                }
                textView.text = UIHelperBp.getString(R.string._hypotensive_stage_1_str)
            }

            4 -> {
                if (changeTextColor == 1) {
                    textView.setTextColor(UIHelperBp.getColor(R.color.color_FF9501))
                }
                textView.text = UIHelperBp.getString(R.string._hypotensive_stage_2_str)
            }

            else -> {
                if (changeTextColor == 1) {
                    textView.setTextColor(UIHelperBp.getColor(R.color.color_F64A10))
                }
                textView.text = UIHelperBp.getString(R.string._hypotensive_crisis_str)
            }
        }
    }

    @BindingAdapter("android:setEmoticonsScopeText")
    @JvmStatic
    fun setEmoticonsScopeText(textView: TextView, enum: Int?) {
        if (enum == null)
            return
        when (enum) {
            0 -> {
                textView.text = Constants.HYPOTENSIVE_SIZE
            }

            1 -> {
                textView.text = Constants.NORMAL_SIZE
            }

            2 -> {
                textView.text = Constants.ELEVATED_SIZE
            }

            3 -> {
                textView.text = Constants.STAGE1_SIZE
            }

            4 -> {
                textView.text = Constants.STAGE2_SIZE
            }

            else -> {
                textView.text = Constants.CRISIS_SIZE
            }
        }
    }


    @BindingAdapter("android:setBloodPressureItemBg")
    @JvmStatic
    fun setBloodPressureItemBg(constraintLayout: ConstraintLayout, degree: Int?) {
        if (degree == null)
            return
        when (degree) {
            0 -> {
                constraintLayout.background =
                    (UIHelperBp.getDrawable(R.mipmap.history_item_hypotensive_item_bp))
            }

            1 -> {
                constraintLayout.background =
                    (UIHelperBp.getDrawable(R.mipmap.history_item_normal_item_bp))
            }

            2 -> {
                constraintLayout.background =
                    (UIHelperBp.getDrawable(R.mipmap.history_item_elevated_item_bp))
            }

            3 -> {
                constraintLayout.background =
                    (UIHelperBp.getDrawable(R.mipmap.history_item_stage_1_item_bp))
            }

            4 -> {
                constraintLayout.background =
                    (UIHelperBp.getDrawable(R.mipmap.history_item_stage_2_item_bp))
            }

            else -> {
                constraintLayout.background =
                    (UIHelperBp.getDrawable(R.mipmap.history_item_crisis_item_bp))
            }
        }
    }


    @BindingAdapter("setBloodPressureItemLineResources")
    @JvmStatic
    fun setBloodPressureItemLineResources(imageView: ImageView, degree: Int) {
        when (degree) {
            0 -> {
                imageView.setImageDrawable((UIHelperBp.getDrawable(R.drawable.line_hypotensive_bp)))
            }

            1 -> {
                imageView.setImageDrawable((UIHelperBp.getDrawable(R.drawable.line_normal_bp)))
            }

            2 -> {
                imageView.setImageDrawable((UIHelperBp.getDrawable(R.drawable.line_elevated_bp)))
            }

            3 -> {
                imageView.setImageDrawable((UIHelperBp.getDrawable(R.drawable.line_stage_1_bp)))
            }

            4 -> {
                imageView.setImageDrawable((UIHelperBp.getDrawable(R.drawable.line_stage_2_bp)))
            }

            else -> {
                imageView.setImageDrawable((UIHelperBp.getDrawable(R.drawable.line_crisis_bp)))
            }
        }
    }

    @BindingAdapter("android:setExclusiveAdviceText")
    @JvmStatic
    fun setExclusiveAdviceText(textView: TextView, enum: Int?) {
        if (enum == null)
            return
        when (enum) {
            0 -> {
                textView.text = UIHelperBp.getString(R.string._exclusive_advice_hypotension_str)
            }

            1 -> {
                textView.text = UIHelperBp.getString(R.string._exclusive_advice_nomarl_str)
            }

            2 -> {
                textView.text = UIHelperBp.getString(R.string._exclusive_advice_elevated_str)
            }

            3 -> {
                textView.text =
                    UIHelperBp.getString(R.string._exclusive_advice_hypertension_stage1_str)
            }

            4 -> {
                textView.text =
                    UIHelperBp.getString(R.string._exclusive_advice_hypertension_stage2_str)
            }

            else -> {
                textView.text =
                    UIHelperBp.getString(R.string._exclusive_advice_hypertension_crisis_str)
            }
        }
    }
}
